﻿using Newtonsoft.Json;

namespace Games.Data
{
    public abstract class BaseArgs
    {
        [JsonIgnore]
        public int ID { get; set; }
        public string GameID { get; set; }
        public string Version { get; set; }
        [JsonIgnore]
        public string Json { get; set; }
        public static T Convert<T>(GameArgs gameArgs) where T : BaseArgs, new()
        {
            var t = JsonConvert.DeserializeObject<T>(gameArgs.Json);
            t.Json = gameArgs.Json;
            t.ID = gameArgs.ID;
            t.GameID = gameArgs.GameID;
            t.Version = gameArgs.Version;
            return t;
        }

        public GameArgs ToGameArgs()
        {
            return new GameArgs
            {
                Json = JsonConvert.SerializeObject(this),
                GameID = this.GameID,
                Version = this.Version,
                ID = this.ID
            };
        }
    }
}
